/*
题目链接:https://leetcode.cn/problems/maximum-or/description/?envType=daily-question&envId=2025-03-21
*/

//题解代码:
class Solution {
public:
    #define ll long long 
    long long maximumOr(vector<int>& nums, int k) {
        int n = nums.size();
        vector<ll> pre(n+1),suf(n+2);
        for(int i=1;i<=n;++i) pre[i] = pre[i-1] | nums[i-1];
        for(int i=n-1;i>=0;--i) suf[i] = suf[i+1] | nums[i];
        ll ans = 0;
        for(int i=0;i<n;++i){
            ans = max(ans,pre[i]|suf[i+1]|(1LL<<k)*nums[i]);
        }
        return ans;
    }
};
